<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<style>
.page-wrapper{display:block;}
</style>
<div id="search-header">
<div id="search-header-content" class="clear">
<a href="webindex.do"><img src="${path}/base/img/logo.png" class="logo"/></a>
<div class="search-top">
<div class="search-input clear">
<input id="keyword" name="keyword" type="text" value="请输入书名"/>
<a class="search-button" href="#"><img src="${path}/base/img/search-button.jpg"/></a>
<a class="search-list-show" href="#">按学校搜索</a>
</div>
<div class="search-info">
<p>官方客服QQ ：
<a href="tencent://message/?uin=1910090073&Site=&Menu=yes"><img src="${path}/base/img/qq.png"/>&nbsp;1910090073
</a>
</p>
</div>
</div>

<div class="search-bottom hide">
    <div class="search-bottom-wrapper">
        <h4>根据院系可以实现学长学姐书籍薪火相传</h4>
        <div class="search-bottom-area clear">
        <input name="school" id="school-input" class="search-bottom-input" type="text" value="请选择大学"/>
        <ul id="depart-input" class="search-bottom-input"><span class="major-text">院系</span></ul>
        <ul id="major-input" class="search-bottom-input"><span class="major-text">专业</span></ul>
        <input type="button" id="school-search" value="搜索"/>
        </div>
    </div>
</div>

</div>
</div>
<div style="display:none; position:absolute;width: 100%; height:100%;top: 0px; left: 0px;z-index:90000;" id="school-dialog">
			    <div class="mask"></div>
				<div class="ma clear" style="height:400px;width:700px;margin:0 auto;left:25%;">
					<div class="close" id="school-close"></div>
					<h2 style="width:100%;font-size:15px; font-weight:bolder;margin:5px 0; text-align:left;height:40px;line-height:40px;border-bottom:2px solid #ff6600">选择学校</h2>
					<div class="schools">
					</div>
					<div class="schools-page clear">
                       <a href="#" class="school-pre-page">上一页</a>
                       <a href="#" class="school-next-page">下一页</a>
					</div>
				</div>
</div>

<script type="text/javascript">
var tip = "请输入书名";
var tipS = "请选择大学";
var schoolPageIndex = 0;
var schoolPageSize = 20;
var schoolPageTotal;
document.onkeydown=function(event){
var e = event || window.event || arguments.callee.caller.arguments[0];
if(e && e.keyCode==27){ // 按 Esc 
//要做的事情
}
if(e && e.keyCode==113){ // 按 F2 
//要做的事情
} 
if(e && e.keyCode==13){ // enter 键
   var act = document.activeElement.id;
   if(act == "keyword"){
      search();
   }
  
}
}; 

function search(){
   var val = $("#keyword").val();
        if(val == '' || val == tip){
            alert("请输入正确的检索词");
            return;
        }
    location.href="search.do?key="+val;
}
$(function(){
     $(".school-pre-page").click(function(){
		        if(schoolPageIndex == 0){
		            alert("当前已经是第一页");
		            return;
		        }
		        schoolPageIndex--;
		        $(".schools-page a").each(function(){
		            $(this).removeClass("now");
		            if($(this).attr("name") == "page-"+schoolPageIndex){
		                $(this).addClass("now");
		            }
		        });
		        getSchool();
		    });
		    
		$(".school-next-page").click(function(){
		        if(schoolPageIndex == schoolPageTotal-1){
		            alert("当前已经是最后一页");
		            return;
		        }
		        schoolPageIndex++;
		        $(".schools-page a").each(function(){
		            $(this).removeClass("now");
		            if($(this).attr("name") == "page-"+schoolPageIndex){
		                $(this).addClass("now");
		            }
		        })
		        getSchool();
		   });
    
    
    $("ul.search-bottom-input span").click(function(){
       var s = $(this);
       s.parent().find("li").toggle();
    })

    $(".search-list-show").click(function(){
        $(".search-bottom").toggle();
        if($(".search-bottom").css("display") == "block"){
             getSchool();
        }
    })
    

    $(".search-button").click(function(){
       search();
    })
    
    $("#school-search").click(function(){
        var school = $("#school-input").val();
        var scode = $("#school-input").attr("code");
        var sid = $("#school-input").attr("sid");
        var depart = $("#depart-input").find("span").eq(0).text();
        var dcode = $("#depart-input").find("span").eq(0).attr("code");
        var did = $("#depart-input").find("span").eq(0).attr("id");
        var major = $("#major-input").find("span").eq(0).text();
        var mcode = $("#major-input").find("span").eq(0).attr("code");
        var mid = $("#major-input").find("span").eq(0).attr("id");
        //alert(school + "   " + depart + "   " + major);
        //alert(scode + "   " + dcode + "   " + mcode);
        if(school == tipS || depart == "院系"){
            alert("请选择正确的检索信息");
            return ;
        }
        if(major=='专业'){
            mcode = "";
            mid = "";
        }
        location.href="searchschool.do?school="+school+"&scode="+scode+"&depart="+depart+"&dcode="+dcode+"&major="+major+"&mcode="+mcode+"&sid="+sid+"&did="+did+"&mid="+mid;
    });
    
    $("#school-input").focusin(function(){
        openDialogSchool();
    })
    
    
    
    $("#keyword").focusin(function(){
        var t = $(this);
        if(t.val() == tip){
           t.val("");
        }
    })
    
    $("#keyword").focusout(function(){
      var t = $(this);
        if(t.val() == ''){
           t.val(tip);
        }
    })
    
    $("#school-close").click(function(){
	  $("#school-dialog").css("display", "none");
   })
    
});

 function getSchool(){
   request("listSchool.do","pageIndex="+schoolPageIndex+"&pageSize="+schoolPageSize+"&isNotPage=0",function(data){
                var d = data.data;
                $("#school-dialog .ma p").remove();
                for(var i =0 ; i < d.length; i+=4){
                    var row = $('<p class="clear"><span></span><span></span><span></span><span></span></p>');
                    for(var k = 0 ; k < 4; k++){
                       if(i+k >= d.length){
                          break;
                       }
                       var s = d[i+k];
                       row.find("span").eq(k).text(s.name);
                       row.find("span").eq(k).attr("id",s.id);
                       row.find("span").eq(k).attr("code",s.code);
                    }
                    $("#school-dialog .ma .schools").append(row);
                }
                //处理分页
                var stotal = data.total;
		        //计算总页数
		        schoolPageTotal = Math.ceil(stotal / schoolPageSize);
		       //对分页进行处理
		       if(schoolPageTotal > 1){
		          $(".schools-page").show();
		          $(".school-page-num").remove();
		          for(var i = 1 ; i <= schoolPageTotal ; i++){
		            var row = $('<a class="school-page-num" href="#"></a>');
		            row.text(i);
		            row.attr("name","page-"+(i-1));
		            row.insertBefore($(".school-next-page"));
		            if(schoolPageIndex == (i-1)){
		               row.addClass("now");
		            }
		           }
		          $(".school-page-num").click(function(){
		             if(!$(this).hasClass("now")){
		                pageIndex = parseInt($(this).text())-1;
		                getSchool();
		             }
		          });
		        }else{
		            $(".schools-page").hide();
		        }
                $("#school-dialog .ma p span").click(function(){
                    var value =$(this).text();
                    $("#school-dialog").css("display", "none");
                    $("#school-input").val(value);
                    $("#school-input").attr("code",$(this).attr("code"));
                    $("#school-input").attr("sid",$(this).attr("id"));
                    //处理后续的院系和专业
                    $("#depart-input li").remove();
                    $("#depart-input").find("span").eq(0).text("院系");
                    $("#depart-input").find("span").eq(0).attr("code","");
                    //处理专业
                    $("#major-input li").remove();
                    $("#major-input").find("span").eq(0).text("专业");
                    $("#major-input").find("span").eq(0).attr("code","");
                    //根据id再去请求院系列表
                    request("listDepartment.do","pageIndex=0&pageSize=100&isNotPage=0&pid="+$(this).attr("id"),function(data){
                        var dd = data.data;
                        for(var i in dd){
                           var dt = dd[i];
                           var rowd = $("<li></li>");
                           rowd.attr("id",dt.id);
                           rowd.text(dt.name);
                           rowd.attr("code",dt.code);
                           $("#depart-input").append(rowd);
                        }
                        $("#depart-input li").click(function(){
                            var s = $(this);
                            s.parent().find("span").eq(0).text(s.text());
                            s.parent().find("span").eq(0).attr("id",s.attr("id"));
                            s.parent().find("span").eq(0).attr("code",s.attr("code"));
                            s.parent().find("li").hide();
                            //处理专业
                            $("#major-input li").remove();
                            $("#major-input").find("span").eq(0).text("专业");
                            $("#major-input").find("span").eq(0).attr("code","");
                            //获取专业列表
                            request("listMajor.do","pageIndex=0&pageSize=100&isNotPage=0&pid="+$(this).attr("id"),function(data){
                                var dd = data.data;
                                for(var i in dd){
                                   var dt = dd[i];
                                   var rowd = $("<li></li>");
                                   rowd.attr("id",dt.id);
                                   rowd.text(dt.name);
                                   rowd.attr("code",dt.code);
                                   $("#major-input").append(rowd);
                                }
                                //专业列表的点击函数
                                 $("#major-input li").click(function(){
                                       var s = $(this);
                                       s.parent().find("span").eq(0).text(s.text());
                                       s.parent().find("span").eq(0).attr("id",s.attr("id"));
                                       s.parent().find("span").eq(0).attr("code",s.attr("code"));
                                       s.parent().find("li").hide();
                                  });
                            });
                            //end of 获取专业列表
                        });
                    });  //end of 院系列表
              })
             });
}

function getDepartment(sid){
     //根据id再去请求院系列表
                    request("listDepartment.do","pageIndex=0&pageSize=100&isNotPage=0&pid="+sid,function(data){
                        var dd = data.data;
                        for(var i in dd){
                           var dt = dd[i];
                           var rowd = $("<li></li>");
                           rowd.attr("id",dt.id);
                           rowd.text(dt.name);
                           rowd.attr("code",dt.code);
                           $("#depart-input").append(rowd);
                        }
                        $("#depart-input li").click(function(){
                            var s = $(this);
                            s.parent().find("span").eq(0).text(s.text());
                            s.parent().find("span").eq(0).attr("id",s.attr("id"));
                            s.parent().find("span").eq(0).attr("code",s.attr("code"));
                            s.parent().find("li").hide();
                            //处理专业
                            $("#major-input li").remove();
                            $("#major-input").find("span").eq(0).text("专业");
                            $("#major-input").find("span").eq(0).attr("code","");
                            //获取专业列表
                            request("listMajor.do","pageIndex=0&pageSize=100&isNotPage=0&pid="+$(this).attr("id"),function(data){
                                var dd = data.data;
                                for(var i in dd){
                                   var dt = dd[i];
                                   var rowd = $("<li></li>");
                                   rowd.attr("id",dt.id);
                                   rowd.text(dt.name);
                                   rowd.attr("code",dt.code);
                                   $("#major-input").append(rowd);
                                }
                                //专业列表的点击函数
                                 $("#major-input li").click(function(){
                                       var s = $(this);
                                       s.parent().find("span").eq(0).text(s.text());
                                       s.parent().find("span").eq(0).attr("id",s.attr("id"));
                                       s.parent().find("span").eq(0).attr("code",s.attr("code"));
                                       s.parent().find("li").hide();
                                  });
                            });
                            //end of 获取专业列表
                        });
                    });  //end of 院系列表
   
}

function getMajors(did){
 //获取专业列表
                            request("listMajor.do","pageIndex=0&pageSize=100&isNotPage=0&pid="+did,function(data){
                                var dd = data.data;
                                for(var i in dd){
                                   var dt = dd[i];
                                   var rowd = $("<li></li>");
                                   rowd.attr("id",dt.id);
                                   rowd.text(dt.name);
                                   rowd.attr("code",dt.code);
                                   $("#major-input").append(rowd);
                                }
                                //专业列表的点击函数
                                 $("#major-input li").click(function(){
                                       var s = $(this);
                                       s.parent().find("span").eq(0).text(s.text());
                                       s.parent().find("span").eq(0).attr("id",s.attr("id"));
                                       s.parent().find("span").eq(0).attr("code",s.attr("code"));
                                       s.parent().find("li").hide();
                                  });
                            });
                            //end of 获取专业列表
}

function openDialogSchool(){
        var sM = $(document).scrollTop()+100;
	    var h = $("body").height();
	    var w = $("body").width();
	    var wd = $("#school-dialog .ma").width();
		$("#school-dialog").css({"display":"block","height":h});
		$("#school-dialog .ma").css({"left":(w-wd)/2});
		$(".ma").css({"top":sM});
}

</script>